import { Component, OnInit } from '@angular/core';
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
import {format} from "date-fns";

@Component({
  selector: 'app-report-manage',
  templateUrl: './report-manage.component.html',
  styleUrls: ['./report-manage.component.scss']
})
export class ReportManageComponent implements OnInit {
  jrsqIframeSrc: SafeResourceUrl;
  gqjskllReportSrc: SafeResourceUrl;
  ggyysCityReportSrc: SafeResourceUrl;
  ggyysGlcReportSrc: SafeResourceUrl;
  year = new Date().getFullYear();
  month = new Date().getMonth() + 1;
  serverUrl = (window as any).environment.reportUrl;
  token = localStorage.token;

  constructor(private sanitizer: DomSanitizer) { }

  ngOnInit(): void {
    // 今日水情
    const date = format(new Date(), 'YYYY-MM-DD');
    const paramStr = `&year=${this.year}&month=${this.month}&token=${this.token}`;

    const link1 = `${this.serverUrl}preview?_u=wrs:今日水情.ureport.xml&_t=3,6&date=${date}&token=${this.token}`;
    this.jrsqIframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link1);

    // 干渠进水口流量
    const link2 = `${this.serverUrl}preview?_u=wrs:干渠进水口水位流量.ureport.xml&_t=3,6${paramStr}`;
    this.gqjskllReportSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link2);

    const link3 = `${this.serverUrl}preview?_u=wrs:实时调度_市县用水量.ureport.xml&_t=3,6${paramStr}`;
    this.ggyysCityReportSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link3);

    const link4 = `${this.serverUrl}preview?_u=wrs:实时调度_引水量.ureport.xml&_t=3,6${paramStr}`;
    this.ggyysGlcReportSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link4);

  }

}
